package n13;

import java.util.HashMap;
import java.util.Map;

public class Main1 {
    public static int romanToInt(String s) {
        int result = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            int num = getNum(c+"");
            int nextNum = 0;
            if (i + 1 < s.length()) {
                // 下个字符
                String n = s.charAt(i + 1)+"";
                nextNum = getNum(c + n);
                if (nextNum != 0) {
                    i++;// 跳过
                    result += nextNum;
                    continue;
                }
            }
            result += num;
        }

        return result;
    }
    private static int getNum(String c){

        switch (c){
            case "I":return 1;
            case "V":return 5;
            case "X":return 10;
            case "L":return 50;
            case "C":return 100;
            case "D":return 500;
            case "M":return 1000;
            case "IV":return 4;
            case "IX":return 9;
            case "XL":return 40;
            case "XC":return 90;
            case "CD":return 400;
            case "CM":return 900;
            default:return 0;
        }
    }

    public static void main(String[] args) {
        String[] cases = {
                // "III",
                "MCMXCIV"};
        for (String s : cases) {
            System.out.println(romanToInt(s));
        }
    }
}
